import shelve

nums = shelve.open('numdb')
nums['pi'] = (3.14192,False)
nums['phi'] = (2.1828,False)
nums['perfect'] = (6,True)
nums.close()

numbers = shelve.open('numdb')
for thing in numbers:
    print(thing)

print(numbers['pi'])

numbers.close()    # 使用完 shelve 接口打开字典后必须手动将其关闭，此操作会强制将所有未完成的更改写入文件

